// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.util.list;

import java.util.AbstractList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.RandomAccess;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.UnaryOperator;

public final class PZConvertList<S, T> extends AbstractList<T> implements RandomAccess {
    private final List<S> m_list;
    private final Function<S, T> m_converterST;
    private final Function<T, S> m_converterTS;

    public PZConvertList(List<S> list, Function<S, T> converterST) {
        this(list, converterST, null);
    }

    public PZConvertList(List<S> list, Function<S, T> converterST, Function<T, S> converterTS) {
        this.m_list = (List<S>)Objects.requireNonNull(list);
        this.m_converterST = converterST;
        this.m_converterTS = converterTS;
    }

    public boolean isReadonly() {
        return this.m_converterTS == null;
    }

    public int size() {
        return this.m_list.size();
    }

    public Object[] toArray() {
        return this.m_list.toArray();
    }

    public <R> R[] toArray(R[] object0) {
        int int0 = this.size();

        for (int int1 = 0; int1 < int0 && int1 < object0.length; int1++) {
            Object object1 = this.get(int1);
            object0[int1] = object1;
        }

        if (object0.length > int0) {
            object0[int0] = null;
        }

        return (R[])object0;
    }

    public T get(int _int) {
        return this.convertST((S)this.m_list.get(_int));
    }

    public T set(int _int, T object1) {
        Object object0 = this.get(_int);
        this.setS(_int, this.convertTS((T)object1));
        return (T)object0;
    }

    public S setS(int _int, S object1) {
        Object object0 = this.m_list.get(_int);
        this.m_list.set(_int, object1);
        return (S)object0;
    }

    public int indexOf(Object val) {
        int int0 = -1;
        int int1 = 0;

        for (int int2 = this.size(); int1 < int2; int1++) {
            if (objectsEqual(val, this.get(int1))) {
                int0 = int1;
                break;
            }
        }

        return int0;
    }

    private static boolean objectsEqual(Object object0, Object object1) {
        return object0 == object1 || object0 != null && object0.equals(object1);
    }

    public boolean contains(Object o) {
        return this.indexOf(o) != -1;
    }

    public void forEach(Consumer<? super T> action) {
        int int0 = 0;

        for (int int1 = this.size(); int0 < int1; int0++) {
            action.accept(this.get(int0));
        }
    }

    public void replaceAll(UnaryOperator<T> operator) {
        int int0 = 0;

        for (int int1 = this.size(); int0 < int1; int0++) {
            Object object0 = this.get(int0);
            Object object1 = operator.apply(object0);
            this.set(int0, (T)object1);
        }
    }

    public void sort(Comparator<? super T> c) {
        this.m_list.sort((object1, object0) -> c.compare(this.convertST((S)object1), this.convertST((S)object0)));
    }

    private T convertST(S object) {
        return (T)this.m_converterST.apply(object);
    }

    private S convertTS(T object) {
        return (S)this.m_converterTS.apply(object);
    }
}
